//
// appdic.h
// libprotea
// Tools Library for the Protea Project / Application Dictionary (APPDIC) definitions
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please send correspondence to:
// 
// theproteaproject@gmail.com
//

#ifndef __PROTEA_APPDIC_H__
#define __PROTEA_APPDIC_H__

/**
	\file appdic.h
	\brief Application Dictionary Structure Definitions
*/

const long MAX_FLD_LEN = 254;

const long GCS_APP_NUMBER = -1;

const long MAX_LANGUAGES = 10;

//
// Data-type definitions
//
const long BIG_STRING			=	0;  // ANY CHAR, LEFT JUSTIFIED, UP TO 256 CHARACTERS LONG
const long STRING				=	1;  // ANY CHAR, LEFT JUSTIFIED
const long ALPHA_STRING			=	2;  // ALPHA ONLY, LEFT JUSTIFIED
const long DISPLAY_NUM			=	3;  // BLANK FILLED, LEADING SIGN, DEC PT
const long DEC_FLOAT			=	4;
const long DEC_DOUBLE			=	5;
const long S_INTEGER			=	6;  // 16 BIT INTEGER
const long D_INTEGER			=	7;  // 32 BIT INTEGER

const long DATE_JULIAN			=	8;  // JULIAN DATE
const long DATE_MDY				=	9;  // MMDDYY
const long DATE_MDY_DISPLAY		=	10; // MM/DD/YY
const long DATE_YMD				=	11; // YYMMDD
const long DATE_YMD_DISPLAY		=	12; // YY/MM/DD
const long DATE_DMY				=	13; // DDMMYY
const long DATE_DMY_DISPLAY		=	14; // DD/MM/YY
const long DATE_STR_DISPLAY		=	15; // MONTH DAY, YEAR  EX: MAY 1, 1980
const long DATE_MD				=	16; // MMDD
const long DATE_MD_DISPLAY		=	17; // MM/DD
const long DATE_DM				=	18; // DDMM
const long DATE_DM_DISPLAY		=	19; // DD/MM

const long TIME_12HR			=	20; // HHMMA
const long TIME_12HR_DISPLAY	=	21; // HH:MMA
const long TIME_24HR			=	22; // HHMM
const long TIME_24HR_DISPLAY	=	23; // HH:MM
const long TIME_EU_12HR_DISP	=	24; // HH.MMA
const long TIME_EU_24HR_DISP	=	25; // HH.MM

const long DUR_HH_TIME			=	26; // PACKED HOURS
const long DUR_HH_TIME_DISP		=	27; // +- HOURS.FRACTION
const long DUR_HM_TIME			=	28; // +- HOURSMM
const long DUR_HM_TIME_DISP		=	29; // +- HOURS:MM

const long NUM_LEFT_DISP		=	30;	// DISPLAY NUM LEFT
const long DATE_CENTURY_YEAR	=	31; // CENTURY YEAR 0000-9999
const long DATE_YEAR			=	32; // YEAR 00-99
const long DATE_CYMD			=	33; // CCYYMMDD
const long DATE_MDCY			=	34; // MMDDCCYY
const long DATE_DMCY			=	35; // DDMMCCYY
const long DATE_MDCY_DISPLAY	=	36; // MM/DD/CCYY
const long DATE_DMCY_DISPLAY	=	37; // DD/MM/CCYY
const long DATE_CYM				=	38; // CCYYMM
const long DATE_YMD_USER		=	39; // NOT A0
const long DATE_TIMESTAMP		=	40;	// Timestamp - date and time
const long TIME_24HR_DB			=	41;
const long DATE_DB				=	42;
const long DECIMAL_64			=	43;
const long LITERAL_VAL			=	44;
const long VAR_STRING			=	45; // Varying length string
const long XCBLOB				=	46; // long = size in bytes, long* = pointer to actual BLOB data (outside of actual buffer memory)
const long DB_FUNCTION			=	47;
const long AUTONUMBER			=   48; // Auto Incrementing Number - like MS Access AutoNumber field
const long LITERAL_STRING		=	49;
const long XCBOOL				=	50;

struct appl_defn {
	char	appl_name[256];
	long	appdic_version;
	long	appl_nbr;
	long	unicode_mult;
};


struct data_type_defn {
	long	data_type;
	char	type_name[17];
	char	image_type[3];
	long	std_length;
	long	decimal_places;
	long	cust_version_nbr;
};

struct fmt_type_defn {
	long	format_type;
	char	type_name[17];
	long	cust_version_nbr;
};






struct rsrvd_word_defn {
	char	reserved_word[17];
	long	reserved_nbr;
	long	cust_version_nbr;
};

struct appdic_library {
	char	library[ 81 ];
};



// end Appdic Data Set structs





/*
	Move to combined prep files	
*/

struct offset_info {
	long count;
	long offset;
};

struct buffer_header {
	char	iden[ 4 ];

	long	checksum;
	long	crc32;

	// Format information
	offset_info formats;
	offset_info ds;
	offset_info fields;
	offset_info sysval;

	// Database information
	offset_info	databases;
	offset_info db_tables;
	offset_info db_relate;

	// Not implemented yet, but reserving space
	offset_info transactions;
	offset_info transaction_defns;

	offset_info messages;
	offset_info appl_defn;

	offset_info literals;
	offset_info litgroups;
	offset_info litrelate;

	offset_info user_exits;
	offset_info library;
	offset_info languages;
	offset_info extra[ 8 ];
};


struct buffer_format {
	long	number;				// Format number
	char	name[ 24 ];			// Format name
	char	real_name[ 24 ];	// Real format name (no 00 stuff)
	long	type;				// Format type
	long	length;				// Data size
	long	ds_count;			// Field count

	long	ds_offset;			// Offset to field list
	long	default_offset;		// Offset to default data
	long	dd_offset;			// Offset to dataset_descr record

	bool	indexed;			// Is this buffer indexed? 
	long	reserved1;
	long	reserved2;

	long	child_format;		/// Child format
};


struct buffer_ds {
	long	field_offset;		// Pointer to field data
	long	data_offset;		// Offset of data in buffer data
	long	min_length;			// Minimum field length
	long	max_length;			// Maximum field length
	long	alloc_size;			// Actual size allocated to field
	long	dec_places;			// Number of decimal places
	long	data_type;			// Field data type
	long	flags;				// Flags
	long	index;				// Index to sorted field list

	long	severity_code;		// Severity code
	long	desc_message;		// Description message
};


struct buffer_field {
	long	number;				// Field number
	char	name[ 24 ];			// Field name
	char	real_name[ 24 ];	// Real field name (no 00 stuff)

	long	type;				// Default field type (dynamic creation only)
	long	length;				// Default field length (dynamic creation only)
	long	decimal_places;		// Default field decimal places (dynamic creation only)
	long	flags;				// Default field flags (dynamic creation only)
	long	desc_message;		// Description message
	char	defaultval[256];	// Default value
};



struct buffer_db_defn {
	long	number;				// Database number
	char	name[ 204 ];		// Database name
	char	user[ 36 ];			// User name
	char	pass[ 36 ];			// Password
	long	type;				// Database type
	
	long	table_count;		// Tables associated with database
	long	table_offset;		// Pointer to table list
};


struct buffer_db_tables {
	long	db_offset;			// Pointer to database owner
	long	format;				// Pointer to format owner
	long	view_flag;			// View flag

	long	relate_count;		// Total # of relation records
	long	relate_offset;		// Pointer to relation records
};



struct buffer_db_relate {
	long	field_offset;		// Pointer to field record
	long	format_offset;		// Pointer to the format record
	long	field_tgt_offset;	// Pointer to target field record
	long	type;				// Relation type 
};




struct buffer_msg_hdr {
	long	number;
	long	index;
};


struct buffer_msg_defn {
	long	number;
	long	lang_id;
	char	message[ 256 ];
};



struct language_defn {
	long id;
	char name[16];
	char desc[80];
};



struct transaction_defn {
	long		trans_number;
	char		trans_code[24];
	bool		use_defaults;
	offset_info user_exits;
};



struct transactions {
	long		trans_number;
	long		format_number;
	short int	txn_trigger;
	short int	txn_order;
};


struct user_exit_defn {
	long	number;
	bool	active;
};


struct lit_group {
	char	name[18];
	long	number;
	offset_info literals;
};


struct lit_relate {
	long lit_number;
	long value;
};



#endif

